import React, { Component } from 'react'
import Detail from '../../../../components/ReactRouter/Detail'
import {Link, Route} from 'react-router-dom'
export default class index extends Component {
  state = {
    messageArr: [
      {id: 1, title: '消息1'},
      {id: 2, title: '消息2'},
      {id: 3, title: '消息3'},
    ]
  }
  replaceShow = (id, title) => {
    //params参数
    // this.props.history.replace(`/home/home-message/detail/${id}/${title}`)
    //search参数
    // this.props.history.replace(`/home/home-message/detail?id=${id}&title=${title}`)
    //state参数
    this.props.history.replace(`/home/home-message/detail`, {id, title})
  }
  pushShow = (id, title) => {
    //params参数
    // this.props.history.push(`/home/home-message/detail/${id}/${title}`)
    //search参数
    // this.props.history.push(`/home/home-message/detail?id=${id}&title=${title}`)
    //state参数
    this.props.history.push(`/home/home-message/detail`, {id, title})
  }
  render() {
    const {messageArr} = this.state
    return (
      <div>
        <ul>
          {
            messageArr.map(item => {
              return (
                <li key={item.id}>
                  {/* params参数 */}
                  <Link to={`/home/home-message/detail/${item.id}/${item.title}`}>{item.title}</Link>

                  {/* seach参数 */}
                  {/* <Link to={`/home/home-message/detail?id=${item.id}&title=${item.title}`}>{item.title}</Link> */}

                  {/* state参数 */}
                  {/* <Link to={{pathname:'/home/home-message/detail', state: {id: item.id, title: item.title}}}>{item.title}</Link> */}
                  <button onClick={() => {this.replaceShow(item.id, item.title)}}>replace</button>
                  <button onClick={() => {this.pushShow(item.id, item.title)}}>push</button>
                </li>
              )
            })
          }
        </ul>
        {/* 携带params参数 */}
        {/* <Route path={`/home/home-message/detail/:id/:title`} component={Detail}></Route> */}
        {/* 携带search和state参数 */}
        <Route path={`/home/home-message/detail`} component={Detail}></Route>

      </div>
    )
  }
}
